Skip to content

Allow spaces in the arguments of a CSS mixin in @apply - #20725

Merged
RobinMalfait merged 3 commits into
tailwindlabs:mainfrom
lazerg:fix/issue-20724-apply-mixin-arguments
Nov 16, 2026
Merged

RobinMalfait merged 3 commits into
tailwindlabs:mainfrom
lazerg:fix/issue-20724-apply-mixin-arguments

Conversation

@lazerg

@lazerg lazerg commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

@apply with a CSS mixin threw "You cannot use @apply with both mixins and utilities" as soon as the mixin arguments had a space, e.g. @apply --card(red, 2rem). The params were split on every whitespace, so --card(red, was seen as a mixin and 2rem) as a utility.

The params are now split with segment, so whitespace inside parens, brackets, braces and strings is kept in the same part. The dependency scan and the circular dependency check use the same split, so a mixin argument like card in @utility card { @apply --card({ red, card }, 2rem); } is not read as a utility. A list of valid utilities splits the same way as before.

Fixes #20724

Test plan

  • Added @apply --my-mixin-1(red, 2rem) and @apply --my-mixin-1({ 1px, 2px }, 3px) to the existing "should be usable with CSS mixins" test in index.test.ts. It fails without this change and passes with it.
  • Added a test with @apply --card({ red, card }, 2rem) inside @utility card. It fails with a circular dependency error without this change.
  • pnpm vitest run in packages/tailwindcss: all tests pass.
  • pnpm changelog check passes.

@lazerg
lazerg requested a review from a team as a code owner November 16, 2026 16:16
@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Reviews (4) · Last reviewed commit: "Keep spaces only in the arguments of a C..." · Reviewed by Greptile

Comment thread packages/tailwindcss/src/apply.ts Resolved
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2707c393-a941-409c-97c5-1087b7ad13b2
Commits

Reviewing files that changed from the base of the PR and between 3061bb5 and 736dcab.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

@apply now uses splitApplyParams for candidate collection, dependency resolution, and circular-dependency checks. The parser keeps whitespace within dashed identifiers and tracks source offsets. Tests cover spaced CSS mixin arguments, mixins in custom utilities, mixed mixin-and-utility errors, and utility candidates split at spaces in brackets, parentheses, and strings. The changelog records the fix.

Severity of issue fixed: Medium

Merge Risk: Minimal · previous review 3061b

This change lets @apply keep CSS mixin calls whose arguments contain spaces intact instead of misreading them as utilities. It has tests for the main cases and no remaining concrete merge risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: @apply now accepts spaces inside CSS mixin arguments. The changeset splits @apply params with segment, keeps whitespace inside parens, brackets, braces, and str…
Description check Passed The description explains the bug, the new splitting approach, the effect on the dependency scan and circular-dependency check, and the test plan. It relates directly to the changeset in apply.ts and i…
Linked Issues check Passed [#20724] The issue requires @apply --card(red, 2rem) and @apply --card({ 1px, 2px }, 3px) to keep the CSS mixin without the "both mixins and utilities" error. It also requires utility lists to spl…
Out of Scope Changes check Passed The whole-PR apply.ts diff changes only @apply parameter tokenization in substituteAtApply and resolveApplyDependencies, plus the offset accounting that the new tokenization needs, and adds th…
Full details: Title check

Explanation

The title states the main change: @apply now accepts spaces inside CSS mixin arguments. The changeset splits @apply params with segment, keeps whitespace inside parens, brackets, braces, and strings, and adds tests for mixin arguments with spaces. The title matches the primary fix.

Full details: Description check

Explanation

The description explains the bug, the new splitting approach, the effect on the dependency scan and circular-dependency check, and the test plan. It relates directly to the changeset in apply.ts and index.test.ts.

Full details: Linked Issues check

Explanation

[#20724] The issue requires @apply --card(red, 2rem) and @apply --card({ 1px, 2px }, 3px) to keep the CSS mixin without the "both mixins and utilities" error. It also requires utility lists to split as before. I read the whole-PR apply.ts diff (merge base to head). The new splitApplyParams generator replaces whitespace with spaces, splits with segment(..., ' '), and yields dashed identifiers whole through isDashedIdent. Other parts split at each whitespace, as the old split(/\s+/g) did. Offsets advance by one per separator, including empty parts. substituteAtApply (candidate collection and offset tracking) and resolveApplyDependencies (dependency scan and circular check) both use this helper. So --card(red, 2rem) and --card({ 1px, 2px }, 3px) stay one mixin part, and the card word inside @utility card is not read as a utility. Utility candidates such as bg-[rgb(1, 2, 3)] still split at whitespace, so their behavior is unchanged. The test-file additions were taken from the PR description and the summary, not from a full diff read. I did not run the test suite. The previous assessment described an earlier split-everything approach. Its conclusion still holds for the current refined logic that I read.

Full details: Out of Scope Changes check

Explanation

The whole-PR apply.ts diff changes only @apply parameter tokenization in substituteAtApply and resolveApplyDependencies, plus the offset accounting that the new tokenization needs, and adds the splitApplyParams and isDashedIdent helpers. All of these serve #20724. The summary reports test additions in index.test.ts for mixin arguments, and a changelog entry in .changelog/apply-mixin-arguments-with-spaces.md. Both support the fix. The summary reports no changes to exported declarations. No unrelated change is demonstrated. Test-file and changelog contents were taken from the summary, not from a full diff read.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fd954865-925d-4fcc-a4b6-aa96aadf498b
Commits

Reviewing files that changed from the base of the PR and between e811a49 and 3061bb5.

Files selected for processing: 2

  • packages/tailwindcss/src/apply.ts
  • packages/tailwindcss/src/index.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 368d14a8-a2e0-4b49-b364-6e6ebfa65916
Commits

Reviewing files that changed from the base of the PR and between b08bf83 and 058f4c3.

Files selected for processing: 3

  • .changelog/apply-mixin-arguments-with-spaces.md
  • packages/tailwindcss/src/apply.ts
  • packages/tailwindcss/src/index.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread packages/tailwindcss/src/apply.ts Resolved
@RobinMalfait
RobinMalfait self-requested a review November 16, 2026 16:46
@RobinMalfait RobinMalfait self-assigned this Nov 16, 2026
lazerg and others added 3 commits November 16, 2026 19:28
The previous commits split all `@apply` params with `segment`. That also
kept the spaces inside the brackets, parens and strings of utilities, so
`@apply bg-[rgb(1, 2, 3)]`, `@apply [margin:1px 2px]` and
`@apply content-['a b']` started to compile. No class in a template can
contain a space, so `@apply` should not allow it either.

`splitApplyParams` now keeps a part whole only when it is a dashed ident
(a CSS mixin, like `--card(red, 2rem)`). Every other part is split at
each whitespace, as before. All three readers of the params (the
dependency scan, the circular dependency check and the substitution) use
it, with the offsets of each part for the source maps.
@RobinMalfait
RobinMalfait force-pushed the fix/issue-20724-apply-mixin-arguments branch from 3061bb5 to 736dcab Compare November 16, 2026 18:29
@RobinMalfait
RobinMalfait enabled auto-merge (squash) November 16, 2026 18:29

@RobinMalfait RobinMalfait left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Also thanks for making the dependency scan split the params the same way.

Sent by an AI assistant on behalf of @RobinMalfait.

@RobinMalfait
RobinMalfait merged commit 1bea2b0 into tailwindlabs:main Nov 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@apply of a CSS mixin with a space in its arguments gives the error "both mixins and utilities"

2 participants